import { FormSchema } from "@/components/Form";
import { BasicColumn } from "@/components/Table";
import { useDict } from "@/utils/dict/dict";
const res: any = await useDict("log_bussiness_type","log_status","log_login_status");
function findLabel(type,value){
  let label = '';
  res[type].value.forEach(item => {
    if(item.value == value){
      label = item.label;
    }
  });
  return label;
}
export const sysLogcolumns: BasicColumn[] = [
  {
    title: '日志编号',
    dataIndex: 'operId',
  },
  {
    title: '日志模块',
    dataIndex: 'title',
    width: 180,
  },
  {
    title: '操作类别',
    dataIndex: 'operatorType',
    customRender: ({ text }) => {
      return findLabel('log_bussiness_type',text);
    },
  },
  {
    title: '操作人员',
    dataIndex: 'operName',
  },
  {
    title: '操作地址',
    dataIndex: 'operIp',
  },
  {
    title: '操作状态',
    dataIndex: 'status',
    customRender: ({ text }) => {
      return findLabel('log_status',text);
    },
  },
  {
    title: '操作时间',
    dataIndex: 'operTime',
    width: 180,
    customRender: ({ text }) => {
      //时间戳转换位时间
      const date = new Date(text);
      const Y = date.getFullYear() + '-';
      const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      const D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
      const h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
      const m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
      const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
      return Y + M + D + h + m + s;
    }
  },

];
export const searchFormSchema: FormSchema[] = [
  {
    field: 'title',
    label: '操作模块',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'operName',
    label: '操作人员',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: res.log_status.value,
    },
    colProps: { span: 6 },
  },
  {
    field: 'businessType',
    label: '类型',
    component: 'Select',
    defaultValue: [],
    componentProps: {
      options: res.log_bussiness_type.value
    },
    colProps: { span: 6 },
  },
  {
    field: 'date',
    label: '时间范围',
    component: 'RangePicker',
    colProps: {
      span: 12,
    },
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'HH:mm:ss' },
    },
  }
];
export const loginColumns: BasicColumn[] = [
  {
    title: '编号',
    dataIndex: 'infoId',
  },
  {
    title: '用户账号',
    dataIndex: 'userName',
  },
  {
    title: '登录IP地址',
    dataIndex: 'ipaddr',
  },
  {
    title: '登录地点',
    dataIndex: 'loginLocation',
  },
  {
    title: '浏览器类型',
    dataIndex: 'browser',
  },
  {
    title: '操作系统',
    dataIndex: 'os',
  },
  {
    title: '登录状态',
    dataIndex: 'status',
    customRender: ({ text }) => {
      return findLabel('log_login_status',text);
    },
  },
  {
    title: '登录信息',
    dataIndex: 'msg',
  },
  {
    title: '登录时间',
    dataIndex: 'loginTime',
    customRender: ({ text }) => {
      //时间戳转换位时间
      const date = new Date(text);
      const Y = date.getFullYear() + '-';
      const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      const D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
      const h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
      const m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
      const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
      return Y + M + D + h + m + s;
    }
  },
  ]
export const loginsearchFormSchema: FormSchema[] = [
  {
    field: 'userName',
    label: '用户名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: res.log_login_status.value,
    },
    colProps: { span: 6 },
  },
  {
    field: 'date',
    label: '时间范围',
    component: 'RangePicker',
    colProps: {
      span: 12,
    },
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'HH:mm:ss' },
    },
  }
];
